const express = require('express');
const orderModel = require('../model/order')
const router = express.Router()

// 查询所有订单
router.get('/all',async (req,res)=>{
    const dataAll = await orderModel.find()
    res.send({
        mas:'查询成功',
        code:1,
        data:dataAll
    })
})
// 根据订单状态查询
router.get('/state',async (req,res)=>{
    const {state} = request.query;

    const dataAll = await orderModel.find({state})
    res.send({
        mas:'查询成功',
        code:1,
        data:dataAll
    })
})

// 根据id查询
router.get('/byid',async (req,res)=>{
    const {id} = req.id;

    const dataObj= await orderModel.findById(id)
    res.send({
        mas:'查询成功',
        code:1,
        data:dataObj
    })
})

// 添加订单
router.post('/add',async (req,res)=>{
    const {movieId,opearId,seats,code,orderNo,time,state} = request.body;
    const dataObj = await orderModel.create({
                    movieId,
                    opearId,
                    seats,
                    code,
                    orderNo,
                    time,
                    state
                })

    res.send({
        mas:'查询成功',
        code:1,
        data:dataObj
    })
})


module.exports = router;